<?php

/*
 * This file is part of the Geek-Zoo Projects.
 *
 * @copyright (c) 2010 Geek-Zoo Projects More info http://www.geek-zoo.com
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License
 * @author quqiang <quqiang@geek-zoo.com>
 *
 */


require ROOT_PATH.'/Helper/admin_abstract.php';

class Action extends admin_abstract
{
    public function index()
    {
		$status = _GET('recycle', 0);
		 $q = _GET('q');

					if(addslashes($q)){

					$like = " and content LIKE '%$q%' ";
					}else{

					$like = '';
			    }
	    $t=_GET('t'); 
	    if(!$t ){
	    	$t = 'desc';
	    }
	    if($t=='DESC'){
	    	$t = 'asc';
	    }
	    if($t=='ASC'){
	    	$t = 'desc';
	    }
        $getNewrevielwList = _model('post')->getList("where status='$status' ".$like.' order by add_time '.$t, new Pager(20));
        $this->view->assign($getNewrevielwList);
        $this->view->display("admin/content_list.html");
    }
    public function getUserpostList()
    {
        $user_id=_GET('user_id');
        if(!empty($user_id))
        {
            $getUserpostList=_model("post")->getList("where userid={$user_id},oder by id desc", new Pager(20));
        }else
        {
            $this->msg('没有用户ID');
        }
    }
    public function contentRead()
    {
        $id=_GET("id");
        if(!empty($id))
        {
        $newContent=_model("post")->read(array("id"=>$id));
        }else
        {
            $this->msg("没有ID");
        }
        if($newContent)
        {
            $this->view->assign("data", $newContent);
            $this->view->display("admin/content_update.html");
        }
    }
    public function updateContent()
    {
        if(Request::isPost())
        {
            $newarray=array();
            $newRevielw=_POST();
            $flt = array('content');
            foreach ($flt as  $value) {
 
                $newarray[$value]= _POST($value);
            }
            $id=_POST('id');
            $anwser=_model("post")->update(array("id"=>$id), $newarray);
            if($anwser)
            {
                $this->msg("修改成功", "admin/content_manage");
            }
            else
            {
                $this->msg("修改失败");
            }
        }
        
    }
    public function deleteContent()
    {   
				if(Request::isPost())
				{
				   $id=array_filter(_POST("id", array()));
						if ($id) {
							foreach ($id as $key => $value) {
							     $anwser=_model("post")->update(array('id'=>$value), array('status'=>'1'));
							}
						}
				}else{
				   $id=_GET("id", 0);
					 if ($id) {
					   $anwser=_model("post")->update(array("id"=>$id), array('status'=>'1'));
					 }
				}
				$this->redirect("admin/content_manage");
    }


		function redelete()
		{
			$id = _GET('id', 0);
			if ($id) {
				 _model("post")->update(array("id"=>$id), array('status'=>'0'));
			}
			$this->redirect("admin/content_manage?recycle=1");
      
		}
		
		function truedelete()
		{
       if(Request::isPost())
         {
             $id=_POST("id", array());
             $newId=implode(",", $id);
             $anwser=_model("post")->delete("where id in ({$newId})");
         }else{
             $id=_GET("id", 0);
             $anwser=_model("post")->delete(array("id"=>$id));               
         }
         $this->redirect("admin/content_manage?recycle=1");
		}



}
?>
